package org.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.example.common.R;
import org.example.pojo.entity.ApUser;
import org.example.service.ApUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * APP用户信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-26
 */
@RestController
@RequestMapping("/api/article/user")
public class ApUserController {

    @Autowired
    private ApUserService apUserService;


    /**
     * 获取平台用户列表
     *
     * @param page
     * @param size
     * @param userName
     * @param phonenumber
     * @param status
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "分页获取用户数据", notes = "分页获取用户数据", httpMethod = "GET")
    @GetMapping("/list/{page}/{size}")
    public R getUserList(@PathVariable(required = false) Integer page,
                         @PathVariable(required = false) Integer size,
                         @RequestParam(required = false) String userName,
                         @RequestParam(required = false) String phonenumber,
                         @RequestParam(required = false) String status,
                         @RequestParam(required = false) String startTime,
                         @RequestParam(required = false) String endTime
    ) {
        Page<ApUser> userPage = apUserService.pageList(page, size, userName, phonenumber, status, startTime, endTime);

        return R.ok(userPage);
    }


    /**
     * 启用/禁用
     *
     * @param userId
     * @return
     */
    @GetMapping("/status")
    public R status(@RequestParam Integer userId, @RequestParam int status) {
        apUserService.status(userId, status);
        return R.ok("操作成功");
    }

}
